 //
//  ClassificationListTableViewController.m
//  BakeCenter
//
//  Created by 杨洋 on 15/9/21.
//  Copyright (c) 2015年 Baked. All rights reserved.
//

#import "ClassificationListTableViewController.h"
#import "ClassificationListTableViewCell.h"
#import "ClassificationListModel.h"
@interface ClassificationListTableViewController ()
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ClassificationListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[ClassificationListTableViewCell class] forCellReuseIdentifier:@"myCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self reloadDataWithJason];
}
#pragma mark ----- 数据解析 -----
- (void)reloadDataWithJason
{
   [LORequestManger GET:[NSString stringWithFormat:kClassListUrl, self.urlStr] success:^(id response) {
       NSDictionary *dic = (NSDictionary *)response;
       for (NSDictionary *dataDic in dic[@"data"][@"search"][@"list"][@"recipe"][@"data"]) {
           ClassificationListModel *model = [ClassificationListModel shareWithDictionary:dataDic];
           [self.dataArray addObject:model];
       }
       [self.tableView reloadData];
   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       NSLog(@"%@", error);
   }];
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ClassificationListTableViewCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
    ClassificationListModel *model = self.dataArray[indexPath.row];
    [listCell shareCellWithModel:model];
    return listCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
